package com.wxyzz.canteenadmin.order.orderList.controller;

import com.github.pagehelper.PageInfo;
import com.wxyzz.canteenadmin.order.orderList.param.OrderParam;
import com.wxyzz.canteenadmin.order.orderList.service.OrderService;
import com.wxyzz.canteenadmin.order.orderList.vo.MemberInfoVo;
import com.wxyzz.canteenadmin.order.orderList.vo.OrderListVo;
import com.wxyzz.canteencommon.common.R;
import com.wxyzz.canteencommon.entity.ordermanager.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order/orderList")
public class OrderController {

    @Autowired
    private OrderService orderService;

    // 查询
    @GetMapping("/getOrder")
    public R getOrder(OrderParam orderParam) {
        PageInfo<OrderListVo> order = orderService.getOrder(orderParam);
        return R.ok(order);
    }

    // 查询某一个数据
    @GetMapping("/getOneOrder")
    public R getOneOrder(Integer orderId) {
        OrderListVo oneOrderById = orderService.getOneOrderById(orderId);
        return R.ok(oneOrderById);
    }

    // 更新
    @PostMapping("/updateOrderList")
    public R updateOrderList (@RequestBody Order order) {
        System.out.println(order);
        orderService.updateOrder(order);
        return R.ok();
    }

    // 删除
    @PostMapping("/deleteOrderList")
    public R deleteOrderList(Integer orderId) {
        orderService.deleteOrder(orderId);
        return R.ok();
    }

    // 通过订单号查询会员信息
    @GetMapping("/getMemberInfo")
    public R getMemberInfo(String orderNumber) {
        MemberInfoVo memberInfoByOrderNumber = orderService.getMemberInfoByOrderNumber(orderNumber);
        return R.ok(memberInfoByOrderNumber);
    }

    // 查询某个数据通过订单号
    @GetMapping("/getOrderByOrderNumber")
    public R getOrderByOrderNumber(String orderNumber) {
        OrderListVo orderByOrderNumber = orderService.getOrderByOrderNumber(orderNumber);
        return R.ok(orderByOrderNumber);
    }

}
